package com.morgan.storagepermission

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.morgan.storageperlib.saf.ReadStringHandler

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


//       window.decorView.postDelayed({
//           ExternalStorageManager.getInstance().writeTxtGreaterQ(this, "test test 0\r\n", true) {success ->
//               Log.e("morgan", "onCreate: writeTxtGreaterQ:success:$success")
//           }
//       }, 2000)

//        val handler = OpenFolderHandler(this) {uri ->
//            Log.e("morgan", "onCreate: OpenFolderHandler:uri:$uri")
//        }
//        val handler = CreateFileHandler("test0/test1", "text/plain", "one.txt", this) { success, doc, uri ->
//            Log.e("morgan", "onCreate: CreateFileHandler:success:$success, doc:$doc, uri:$uri")
//        }
//        val content = "this is a test txt!"
//        val handler = WriteFileHandler("test0/test1", "text/plain", "one.txt", content.toByteArray(), true,this) { success, uri, output ->
//            Log.e("morgan", "onCreate: WriteFileHandler:success:$success, uri:$uri")
//            if (success) {
//                output?.write("\r\nthis is output first".toByteArray())
//            }
//            Utils.closeQuietly(output)
//        }
        val handler = ReadStringHandler(this) {success, uri, content ->
            Log.e("morgan", "onCreate: ReadStringHandler:success:$success, uri:$uri")
            Log.e("morgan", "onCreate: ReadStringHandler:content:$content")
        }

        window.decorView.postDelayed({
//            handler.launch()
            handler.openFile()
        }, 2000)
    }
}